import { url_video } from "@/comm/api";
import { get, patch, post, remove } from "@/comm/request";
import { defineStore } from "pinia";

interface IPot {
    x: number;
    y: number;
}

export type PKey = "lt" | "rt" | "lb" | "rb"

const defaultStore = {
    cur: null as any,
    lt: { x: 0, y: 0 } as IPot,
    rt: { x: 0, y: 0 } as IPot,
    lb: { x: 0, y: 0 } as IPot,
    rb: { x: 0, y: 0 } as IPot,
}

export const usePositionStore = defineStore({
    id: "position",
    state: () => defaultStore,
    actions: {
        reset(type: PKey) {
            switch (type) {
                case "lt":
                    this.rt.y = this.lt.y;
                    this.lb.x = this.lt.x;
                    break;
                case "rt":
                    this.lt.y = this.rt.y;
                    this.rb.x = this.rt.x;
                    break;
                case "lb":
                    this.rb.y = this.lb.y;
                    this.lt.x = this.lb.x;
                    break;
                case "rb":
                    this.lb.y = this.rb.y;
                    this.rt.x = this.rb.x;
                    break;
            }

        },
        changePosition(x: number, y: number, type: PKey) {
            this[type].x = x;
            this[type].y = y;
            this.reset(type);
        }
    }
});